//
//  KDBodyView.m
//  PublicSentimentMonitorSystem
//
//  Created by 魏强 on 15/6/9.
//  Copyright (c) 2015年 魏强. All rights reserved.
//

#import "KDBodyView.h"
#import "KDHomeThemeModel.h"
#import "HomeCell2.h"
#import "KDBodyViewModel.h"
#import "KDHomeThemeLinkModel.h"
#import "KDHomeThemeModel.h"
#import "KDHomeThemeCell.h"
#import "KDHomeListPageGetMonitorWebListParam.h"
#import "KDHomeListPageGetMonitorWebListResult.h"
#import "KDHomeListPageCellModel.h"
#import "KDBaseBoardModel.h"
#import "KDHomeRequestTool.h"
#import "KDBaseBoard.h"
#import "GBSingleWebViewController.h"
#import "KDReportController.h"
#import "KDBaseBoardTool.h"
#import "SVProgressHUD.h"
#define BTN_WIDTH 75
@interface KDBodyView ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate,HomeCell2Delegate>
@property (nonatomic, strong) UIScrollView *detailScrollView;
@property (nonatomic, strong) UIButton *selectDetailBtn;
@property (nonatomic, strong) UIScrollView *bodyScrollView;
/** 当前显示的tableView*/
@property (nonatomic, strong) UITableView *currentTabV;
/** 当前的baseBoardModel*/
@property (nonatomic, strong) KDBaseBoardModel *baseBoardModel;
/** 默认的baseBoardModel*/
@property (nonatomic, strong) KDBaseBoardModel *defaultBaseBoardModel;

/**
 * tableView的model的数据*
 */
@property (nonatomic, strong) NSDictionary *dataDic;

/**
 *  加载第几页
 */
@property (nonatomic, strong) NSString *page;
/**
 *  所有的列表数据
 */
@property (nonatomic, strong) NSArray *infoArr;
/**
 *  装所有主题model的arr
 */
@property (nonatomic, strong) NSArray *themeArr;
@property (nonatomic, strong) NSDateFormatter *fmt;
/**
 *  没有数据时的提示
 */
@property (nonatomic, weak) UIView * notice;
@end
@implementation KDBodyView
@synthesize  baseBoardModel = _baseBoardModel;
#pragma mark - 懒加载区
- (NSDateFormatter *)fmt
{
    if (!_fmt) {
        _fmt = [[NSDateFormatter alloc]init];
        _fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];;
        _fmt.dateFormat = @"yyyy-MM-dd";
    }
    return _fmt;
}
- (KDBaseBoardModel *)baseBoardModel
{
    if (!_baseBoardModel) {
        _baseBoardModel = [[KDBaseBoardModel alloc]init];
        _baseBoardModel.webSrcType = @"0";
//        NSDate *newdate = [[NSDate date] initWithTimeInterval:- (24 *60 * 60 * 6 )sinceDate:[NSDate date]];
        _baseBoardModel.startTime = @"1970-01-01";//[self.fmt stringFromDate:newdate];
        _baseBoardModel.endTime = @"";
        _baseBoardModel.subtype = @"0";
        _baseBoardModel.timeIndex = @"9";
        _baseBoardModel.docType = @"0";
        _baseBoardModel.idstr = [NSString stringWithFormat:@"%ld", (long)self.homeThemeModel.ID];
//        _baseBoardModel.showReginType = self.model.showReginType;
//        if (self.model.showReginType == 0) {
//            _baseBoardModel.regionType = 4;
//        }else{
//            _baseBoardModel.regionType = self.model.showReginType;
//        }
        self.defaultBaseBoardModel = _baseBoardModel ;

    }
       return _baseBoardModel;
}
- (void)setHomeThemeModel:(KDHomeThemeModel *)homeThemeModel
{
    _homeThemeModel = homeThemeModel;
    [[NSNotificationCenter defaultCenter] postNotificationName:@"homeThemeModelDidChangeValueNotification" object:nil userInfo:@{@"homeThemeModel":homeThemeModel}];
}
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (NSDictionary *)dataDic
{
    if (!_dataDic) {
        _dataDic = [NSDictionary dictionary];
    }
    return _dataDic;
}
- (NSString *)page
{
    if (!_page) {
        _page = @"1";
    }
    return _page;
}
- (NSArray *)themeArr
{
    if (!_themeArr) {
        _themeArr = [NSArray new];
    }
    return _themeArr;
}
- (NSArray *)infoArr
{
    if (!_infoArr) {
        _infoArr = [NSArray new];
    }
    return _infoArr;
}
/**
 *  初始化方法
 */
+ (instancetype)bodyViewWithFrame:(CGRect)frame
{
    return [[self alloc]initWithFrame:frame];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = BackGroundColor;
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(confirmBtnClick:) name:@"HomeControllerConfirmBtnDidClickNoty" object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(homeControllerTopBtnClick:) name:@"HomeControllerTopicBtnDidClickNotyfication" object:nil];
    }
    return self;
}

- (void)setSelectDetailBtn:(UIButton *)selectDetailBtn
{
    _selectDetailBtn.selected = NO;
    _selectDetailBtn = selectDetailBtn;
    _selectDetailBtn.selected = YES;
}
- (void)setModel:(KDHomeThemeLinkModel *)model
{
    _model = model;
    if (model.info.count != 0) {//如果没有子类，那就不用加一个全部类
        NSMutableArray *tempArr = [NSMutableArray arrayWithArray:model.info];
        KDHomeThemeModel *homeThemeModel = [[KDHomeThemeModel alloc]init];
        KDHomeThemeModel *homeThemeModel2 = model.info[0];
        homeThemeModel.parentName = homeThemeModel2.parentName;
        homeThemeModel.parentid = homeThemeModel2.parentid;
        homeThemeModel.name = @"全部";
        [tempArr insertObject:homeThemeModel atIndex:0];
        self.themeArr = tempArr;
    }else{
        self.themeArr = model.info;
    }
    
    [self setUpBodyScrollView];
}
- (void)setHasDetail:(BOOL)hasDetail
{
    _hasDetail = hasDetail;
    if (hasDetail == YES) {//如果有子集
        [self setUpHeadScrollView];
    }
    //在这里重新确定bodyScrollView的frame：
    self.bodyScrollView.y = CGRectGetMaxY(self.detailScrollView.frame) +10;
    self.bodyScrollView.height = screenH - CGRectGetMaxY(self.detailScrollView.frame) - 64 -10;
//    KDLog(@"%@, %f", NSStringFromCGRect(self.bodyScrollView.frame),self.bodyScrollView.height );

    [self setUpTableView];
}

#pragma mark - 板块布置区
/***  创建头部scrollView */
- (void)setUpHeadScrollView
{
    UIScrollView *scr = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, screenW, 44 -10)];
    self.detailScrollView = scr;
    scr.delegate = self;
    scr.contentSize = CGSizeMake(BTN_WIDTH * self.themeArr.count, 1);
    scr.showsHorizontalScrollIndicator = NO;
    scr.showsVerticalScrollIndicator = NO;
    scr.backgroundColor = [UIColor whiteColor];
    [self addSubview:scr];
    for (int i = 0; i < self.themeArr.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.width = BTN_WIDTH;
        btn.height = scr.height ;
        btn.x = i * btn.width;
        btn.y = 0;
        btn.tag = 100+i;
        btn.titleLabel.font = [UIFont systemFontOfSize:14];
        KDHomeThemeModel *model = self.themeArr[i];
        [btn setTitle:model.name forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(detailBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
        [btn setTitleColor: WQColor(178, 182, 184) forState:UIControlStateNormal];
//        btn setTitleColor: WQColor(107, 114, 124) forState:UIControlStateNormal];
        [btn setTitleColor:WQColor(85, 196, 95) forState:UIControlStateSelected];
        btn.backgroundColor = [UIColor whiteColor];
//        btn.tintColor = KDColor;
        if (btn.tag == 100) {
            self.selectDetailBtn = btn;
        }
        [scr addSubview:btn];
    }
    

}
/***  创建装tableView的scrollView */
- (void)setUpBodyScrollView
{
    UIScrollView * bodyScrollView = [[UIScrollView alloc]init];
    self.bodyScrollView = bodyScrollView;
    bodyScrollView.frame = CGRectMake(0, CGRectGetMaxY(self.detailScrollView.frame), screenW, screenH - CGRectGetMaxY(self.detailScrollView.frame)-49);
    bodyScrollView.delegate = self;
    bodyScrollView.contentSize = CGSizeMake(screenW * self.themeArr.count, 1);
    bodyScrollView.showsHorizontalScrollIndicator = YES;
    bodyScrollView.pagingEnabled = YES;
    bodyScrollView.showsVerticalScrollIndicator = YES;
//    bodyScrollView.panGestureRecognizer.delegate = self;
    [self addSubview:bodyScrollView];
    //初始化主题
    
}
/***  各大主题tableView的设置*/
- (void)setUpTableView
{
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0  , 0, screenW, self.bodyScrollView.height ) style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.tag = 1000;
    tableView.tableFooterView = [UIView new];
    tableView.separatorColor = BackGroundColor;
    tableView.backgroundColor = BackGroundColor;
    self.currentTabV = tableView;
    if (self.themeArr.count == 0) {
        
        KDHomeThemeModel *model = [[KDHomeThemeModel alloc]init];
        model.parentid = self.model.ParentID;
        model.ID = 0;
        self.homeThemeModel = model;
    }else{
        self.homeThemeModel = self.themeArr[0];
    }
    [self.bodyScrollView addSubview:tableView];
    tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    [footer setTitle:@"" forState:MJRefreshStateIdle];
   // 设置footer
    self.currentTabV.footer = footer;
    [self.currentTabV.header beginRefreshing];
}
- (void)setUpNotise{
    UIView * notice = [[UIView alloc]initWithFrame:self.currentTabV.bounds];
    self.notice = notice;
    UILabel * noticeLb = [[UILabel alloc]initWithFrame:self.notice.bounds];
    notice.backgroundColor = BackGroundColor;
    notice.y = 0;
    noticeLb.centerY = noticeLb.height * 0.5;
//    KDLog(@"%@", NSStringFromCGRect(notice.frame));
    noticeLb.text = @"暂时没有满足条件的数据";
    noticeLb.textColor = WQColor(178, 182, 184);
    noticeLb.textAlignment = NSTextAlignmentCenter;
    [notice addSubview:noticeLb];
    self.currentTabV.tableHeaderView = notice;
}
#pragma mark - 事件点击区

/***  细节Btn被点击 */
-(void)detailBtnDidClick:(UIButton *)btn
{
    NSInteger num = btn.tag -100;
    [self.bodyScrollView setContentOffset:CGPointMake(screenW*num, self.bodyScrollView.contentOffset.y) animated:YES];
    [self.bodyScrollView scrollRectToVisible:CGRectMake(screenW * num, self.bodyScrollView.frame.origin.y, screenW, self.bodyScrollView.frame.size.height) animated:YES];
    //被点击的btn的后一个btn
    self.selectDetailBtn = btn;
    [self setUpTitleCenter:btn];
}

#pragma mark - 网络请求区
- (void)loadData
{
    //让currentTabV.tableHeaderView归零
    [self.notice removeFromSuperview];
    self.currentTabV.tableHeaderView.height = 0;
    WS(ws);
    //创建参数
    KDHomeListPageGetMonitorWebListParam *param = [[KDHomeListPageGetMonitorWebListParam alloc]init];
//    self.baseBoardModel = [KDBaseBoardTool baseBoardMoldeWithParams:@{@"idstr":[NSString stringWithFormat:@"%ld",self.homeThemeModel.ID]}];
    if (!self.baseBoardModel){
    }
    if (!self.homeThemeModel) {//如果没有数据，就弹出提示
        [SVProgressHUD showErrorWithStatus:@"无数据" maskType:SVProgressHUDMaskTypeGradient];
        self.currentTabV.footer.hidden = YES;
        [ws.currentTabV.header endRefreshing];
        return;
    }else{self.currentTabV.footer.hidden = NO;}
    param.method = @"getBusinessMonitorWebList";
    KDAccount *accout = [KDAccountTool account];
    param.token = accout.token;
    param.webSrcType = self.baseBoardModel.webSrcType;
    param.docType = self.baseBoardModel.docType;
    param.limit = @"20";
    param.page = @"1";
//    param.regionType = self.baseBoardModel.regionType;
    param.startTime = self.baseBoardModel.startTime;
    param.endTime = self.baseBoardModel.endTime;
    param.subtype = @"0";
    param.keyword = self.baseBoardModel.secondSearch;
    param.businessSubType = [NSString stringWithFormat:@"%ld", (long)self.homeThemeModel.ID];
    param.businessType = [NSString stringWithFormat:@"%ld", (long)self.homeThemeModel.parentid];
    param.sortType = @"0";
    param.comeFrom = @"mobile";
    //    KDLog(@"%@",accout.token);
    
    [KDHomeRequestTool getMonitorWebListWithParam:param success:^(KDHomeListPageGetMonitorWebListResult *responseObejct) {
        if ([responseObejct.status isEqualToString:@"notlogin"]) {//如果被别人强制登陆了
            //写提示“该账号已在别处登录”
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"该账号已在别处登录" message:@"请重新登录" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alertView show];
            [ws.currentTabV.header endRefreshing];
            
        }else{//正常情况下，就加载数据
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            if (!responseObejct.info) {
                [self setUpNotise];
                [ws.currentTabV.header endRefreshing];
                return ;
            }
            
            [dic setObject:responseObejct.info forKey:@(self.homeThemeModel.ID) ];
            
            ws.infoArr = responseObejct.info;
            if (ws.infoArr.count == 0) {
                [self setUpNotise];
            }
            //设置page＝1，方便上拉加载时重新从第一页开始加载,
            
            ws.page = @"1";
            [ws.currentTabV reloadData];
            [ws.currentTabV.header endRefreshing];
            [ws.currentTabV.footer resetNoMoreData];
        }
        
    } faiure:^(NSError *error) {
        [ws.currentTabV.header endRefreshing];
        KDLog(@"%@",error);
        UIAlertView *messageView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"数据请求失败，请检查网络" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [messageView show];
    }];
    
}
- (void)loadMoreData
{
    WS(ws);
    //创建参数
    self.page = [NSString stringWithFormat:@"%ld",(long)self.page.integerValue + 1] ;
    KDHomeListPageGetMonitorWebListParam *param = [[KDHomeListPageGetMonitorWebListParam alloc]init];
    //
    param.method = @"getBusinessMonitorWebList";
    KDAccount *accout = [KDAccountTool account];
    //    accout.userName
    param.token = accout.token;
    param.webSrcType = self.baseBoardModel.webSrcType;
    param.docType = self.baseBoardModel.docType;
    param.limit = @"20";
    param.page = self.page;
    param.startTime = self.baseBoardModel.startTime;
//    param.regionType = self.baseBoardModel.regionType;
    param.endTime = self.baseBoardModel.endTime;
    param.subtype = @"0";
    param.businessSubType = [NSString stringWithFormat:@"%ld", (long)self.homeThemeModel.ID];
    param.businessType = [NSString stringWithFormat:@"%ld", (long)self.homeThemeModel.parentid];
    param.sortType = @"0";
    param.comeFrom = @"mobile";
    //    KDLog(@"%@",accout.token);
    
    [KDHomeRequestTool getMonitorWebListWithParam:param success:^(KDHomeListPageGetMonitorWebListResult *responseObejct) {
        NSMutableArray *arr = [NSMutableArray arrayWithArray:ws.infoArr];
        [arr addObjectsFromArray: responseObejct.info];
        ws.infoArr = arr;
        [ws.currentTabV reloadData];
        [ws.currentTabV.footer endRefreshing];
        if (responseObejct.count == 0) {
            [ws.currentTabV.footer endRefreshing];
        }
    } faiure:^(NSError *error) {
        [ws.currentTabV.footer endRefreshing];
        KDLog(@"%@",error);
        UIAlertView *messageView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"数据请求失败，请检查网络" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [messageView show];
    }];
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    if (scrollView.panGestureRecognizer.numberOfTouches == 2) {
        scrollView.scrollEnabled = NO;
    }else{
        scrollView.scrollEnabled = YES;
    }
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    scrollView.scrollEnabled = YES;
}
//scrollView滑动停止会调动
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView == self.bodyScrollView)
    {
        int num = (int)scrollView.contentOffset.x/screenW;
        UIButton *btn = (UIButton *)[self.detailScrollView viewWithTag:num +100];
        [self adjustFrameWithScrollView:scrollView];
        //判断向左滑还是向右滑
        self.selectDetailBtn = btn;
        [self setUpTitleCenter:btn];
    }
}
/**
 *  将被点击的按钮设置到中间
 */
- (void)setUpTitleCenter:(UIButton *)centerBtn{
    CGFloat offsetX = centerBtn.centerX - screenW *0.5;
    if (offsetX < 0) offsetX = 0;
    
    //获取最大滚动范围
    CGFloat maxOffsetX = self.detailScrollView.contentSize.width - screenW;
    if (offsetX > maxOffsetX) offsetX = maxOffsetX;
    // 滚动标题滚动条
    [self.detailScrollView setContentOffset:CGPointMake(offsetX, 0) animated:YES];
}
/***  当scrollView自动停止的时候会调用（不包括手抓的）*/
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
    if (scrollView == self.bodyScrollView)
    {
        [self adjustFrameWithScrollView:scrollView];
      
    }
}

/***  重新确认CurrentTableView */
- (void)adjustFrameWithScrollView:(UIScrollView *)scrollView
{
//    WS(ws);
    //防止没刷完之前就切换后一直刷的bug
    [self.currentTabV.header endRefreshing];
    NSUInteger num = (NSUInteger)scrollView.contentOffset.x/screenW;
    

    self.currentTabV = (UITableView *)[self.bodyScrollView viewWithTag:1000+num];
    self.homeThemeModel = self.themeArr[num];
    if (!self.currentTabV) { //划到这页，判断这页有无tableView，没有的话就建一个
        UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(screenW *num , 0, screenW, self.bodyScrollView.height) style:UITableViewStylePlain];
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.tag = num + 1000;
        tableView.tableFooterView = [UIView new];
        tableView.backgroundColor = BackGroundColor;
        tableView.separatorColor = BackGroundColor;
        [self.bodyScrollView addSubview:tableView];
        tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
        MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
        [footer setTitle:@"" forState:MJRefreshStateIdle];
        tableView.footer = footer;
        self.currentTabV = tableView;
    }
    self.baseBoardModel = self.defaultBaseBoardModel;
    [self.currentTabV.header beginRefreshing];
    self.infoArr = self.dataDic[@(self.homeThemeModel.ID)];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return self.infoArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HomeCell2 *cell = [HomeCell2 cellWithTableView:tableView];
//    KDLog(@"waimian%d", indexPath.row);

    if (tableView == self.currentTabV) {
        cell.delegate = self;
        if (self.infoArr.count != 0) {
            cell.model = self.infoArr[indexPath.row];
//            KDLog(@"%d\n, title = %@", indexPath.row, cell.model.title);
            cell.model.parentID = [NSString stringWithFormat:@"%ld", (long)self.homeThemeModel.ID];
        }
        return cell;
    }else{
        return cell;
    }
}

- (CGFloat) tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 118;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 118;
}
/**
 *  cell被点击了
 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.currentTabV) {
        if (_delegate && [_delegate respondsToSelector:@selector(KDBodyView:WithKKDHomeListPageCellModel:didSelectRowAtIndexPath:)]) {
            if (self.infoArr.count == 0) {
                return;
            }
            HomeCell2 *cell = (HomeCell2 *)[tableView cellForRowAtIndexPath:indexPath];
            cell.highlight = YES;
            NSMutableArray *arr = [NSMutableArray arrayWithArray:self.infoArr];
            [arr replaceObjectAtIndex:indexPath.row withObject:cell.model];
            self.infoArr = arr;
            KDHomeListPageCellModel *model = self.infoArr[indexPath.row];
            [_delegate KDBodyView:self WithKKDHomeListPageCellModel:model didSelectRowAtIndexPath:indexPath];
            
            
        }
    }
}

#pragma mark - HomeCell2Delegate
- (void)homeCell2:(HomeCell2 *)cell reportBtnClick:(UIButton *)reportBtn
{
    if (_delegate && [_delegate respondsToSelector:@selector(KDBodyView:WithKDHomeListPageCellModel:)]) {
        [_delegate KDBodyView:self WithKDHomeListPageCellModel:cell.model];
    }
}
- (void)homeCell2:(HomeCell2 *)cell relationBtnClick:(UIButton *)relationBtn{
    if (_delegate && [_delegate respondsToSelector:@selector(KDBodyView:relationBtnClickWithModel:)]) {
        [_delegate KDBodyView:self relationBtnClickWithModel:cell.model];
    }
}
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if ([alertView.title isEqualToString:@"该账号已在别处登录"]) {
        switch (buttonIndex) {
            case 0:
                if (_delegate && [_delegate respondsToSelector:@selector(bodyViewDidLoginedByOther:)]) {
                    [_delegate bodyViewDidLoginedByOther:self];
                }
                break;
            default:
                break;
        }
    }
}

#pragma mark - 通知接收区
- (void)confirmBtnClick:(NSNotification *)noty{
    
    //    KDLog(@"%@", noty.userInfo);
    KDBaseBoardModel *model = noty.userInfo[@"baseBoardModel"];
    NSInteger parentId = [noty.userInfo[@"parentId"] integerValue];
    if (self.model.ParentID == parentId) {
        self.baseBoardModel = model;
        [self.currentTabV.header beginRefreshing];
    }
    
}
- (void)homeControllerTopBtnClick:(NSNotification *)noty{
    KDBodyView *bodyView = noty.userInfo[@"currentBodyView"];
    if (self == bodyView) {//还原为默认的那个model
        self.baseBoardModel = self.defaultBaseBoardModel;
        [self.currentTabV.header beginRefreshing];
    }
}

@end
